package com.mstore.dao;

import java.util.List;

import com.mstore.pojo.Reply;

public class ReplyDao extends SuperDao {

	/**
	 * 
	 *查询文本、链接回复
	 */
	public List<Object> watchReply(Reply reply) {
		String hql = "from Reply where eaId = ? and (type = 1 or type = 2)";
		Object[] values = new Object[] { reply.getEaId() };
		return super.getObject(hql, values);
	}

	/**
	 * 
	 * 查询菜单可选回复
	 */
	public List<Object> watchMenuReply(Reply reply) {
		String hql = "from Reply where eaId = ? and type != 4";
		Object[] values = new Object[] { reply.getEaId() };
		return super.getObject(hql, values);
	}

	/**
	 * 
	 *通过type查询回复
	 */
	public List<Object> watchReplyByType(Reply reply) {
		String hql = "from Reply where eaId = ? and type = ?";
		Object[] values = new Object[] { reply.getEaId(), reply.getType() };
		return super.getObject(hql, values);
	}

	/**
	 * 
	 * 保存回复
	 */
	public void saveReply(Reply reply) {
		super.save(reply);
	}

	/**
	 * 通过id查询回复
	 */
	public List<Object> getOneReply(Reply reply) {
		String hql = "from Reply where id = ?";
		Object[] values = new Object[] { reply.getId() };
		return super.getObject(hql, values);
	}

	/**
	 * 
	 * 修改回复
	 */
	public void modifyReply(Reply reply) {
		/*String sql = "update b_reply set title = '" + reply.getTitle()
				+ "', content = '" + reply.getContent() + "' where id = "
				+ reply.getId();
		super.executeUpdate(sql);
*/		
		StringBuilder sb = new StringBuilder();
		sb.append("update b_reply set title = '");
		sb.append(reply.getTitle());
		sb.append("', content = '");
		sb.append(reply.getContent());
		sb.append("' where id = ");
		sb.append(reply.getId());
		super.executeUpdate(sb.toString());
	}

	/**
	 * 
	 * 删除回复
	 */
	public void delReply(Reply reply) {
		super.delete(reply);
	}

	/**
	 * 
	 * 查询关注时回复
	 */
	public List<Object> watchSubscribeReply(Reply reply) {
		String hql = "from Reply where eaId = ? and type = 4";
		Object[] values = new Object[] { reply.getEaId() };
		return super.getObject(hql, values);
	}

	/**
	 * 
	 * 修改关注时回复
	 */
	public void modifySubscribeReply(Reply reply) {
		/*String sql = "update b_reply set content = '" + reply.getContent()
				+ "' where id = " + reply.getId();
		super.executeUpdate(sql);*/
		
		StringBuilder sb = new StringBuilder();
		sb.append("update b_reply set content = '");
		sb.append(reply.getContent());
		sb.append("' where id = ");
		sb.append(reply.getId());

		super.executeUpdate(sb.toString());
	}

	/**
	 * 
	 * 修改多图文
	 */
	public void update(Reply reply) {
		/*String sql = "update b_reply set title = '" + reply.getTitle()
				+ "' where id = " + reply.getId();
		super.executeUpdate(sql);*/
		
		StringBuilder sb = new StringBuilder();
		sb.append("update b_reply set title = '");
		sb.append(reply.getTitle());
		sb.append("' where id = ");
		sb.append(reply.getId());
		
		super.executeUpdate(sb.toString());
	}

}
